
var mongoose = require("mongoose");

var dbhost = "112.126.65.35"
var dbport = 27017
var dbname = "wuhan2004"
var dbuser = "gzh"
var dbpass = "gzhdyf1998lol"

var conn_db_str =  `mongodb://${dbuser}:${dbpass}@${dbhost}:${dbport}/${dbname}`

mongoose.connect(conn_db_str,{
    useNewUrlParser:true,
    useUnifiedTopology:true,
},function(err){
    if(err) {
        console.log("数据库连接失败---"+err)
    }else{
        console.log("数据库连接成功...")
    }
})

const connection  = mongoose.connection;

connection.on("connected",()=>{
    console.log("数据库已连接")
})


connection.on("error",()=>{
    console.log("数据库异常")
})

connection.on("disconnected",()=>{
    console.log("数据库断开连接...")
})

module.exports = connection;